from common import *

def Geturl(url,host):

    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
    driver = webdriver.Chrome(chrome_options=options)

    driver.get(url)

    #wait = WebDriverWait(driver, 2)
    #wait.until(lambda dr: dr.find_element_by_name('body').is_displayed())
    today = time.mktime((datetime.datetime.now() + datetime.timedelta(hours=8)).timetuple())
    result=[]
    cookie = [item["name"] + "=" + item["value"] for item in driver.get_cookies()]
    cookiestr = ';'.join(item for item in cookie)
    mysql.execute("update longzs.`longzs_re` set cookie='{}' where host='{}'".format(cookiestr,host))

    updatecacthcield('tempnr', driver.page_source, url)

    driver.execute_script(filenr("jquery.js"))
    swfstr=driver.execute_script("return $('video').attr('src')")
    result.append(swfstr)
    updatecacthcield('swfstr',swfstr,url)

    message=driver.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/div/div[1]/div[2]/div[2]/div[3]').text
    updatecacthcield('message', message, url)

    driver.quit()
    return

    # 执行该文件的主过程
if __name__ == '__main__':
    url=sys.argv[1]
    Geturl(url, "itouchtv.cn")
    #Geturl("https://www.itouchtv.cn/video/ae5589f548d1f765ff0a509c2c763fcf","itouchtv.cn")
    #cd D:/website/word.longsunhd.com/python && D: && python ku6.com.py https://www.ku6.com/video/detail?id=ezwo2pF-0KTewk5mXSNr1IsuE4E.

